mui.init({
	swipeBack: true
})
mui.plusReady(function() {
	plus.webview.currentWebview().setStyle({
		top: '0',
		bottom: '0'
	})
})
var num = 60
var temp = num
var swithCode = false
var swith = false
//获取验证码
$(".getCode").on("tap", function() {
	if(swithCode) {
		return
	}
	if(!common.phone.test($('.phone input').val())) {
		common.toast('请输入正确的手机号码')
		return
	}
	swithCode = true
	common.ajax('/userCore/sendSMSCode', {
		mobile: $('.phone input').val()
	}, function(data) {
		if(data.code == 1) {
			jishi()
		} else {
			swithCode = false
			if(data.resultMsg) {
				common.toast(data.resultMsg)
			} else {
				console.log(data)
			}
		}
	})
})

//点击注册
$(".register_tap").on("tap", function() {
	if(swith) {
		return
	}
	if(common.replace($('.name input').val()) == '') {
		common.toast('请输入您的姓名或公司名')
		return
	} else if(!common.phone.test($('.phone input').val())) {
		common.toast('请输入正确的手机号码')
		return
	} else if(common.replace($('#code').val()) == '') {
		common.toast('验证码不能为空')
		return
	} else if(common.replace($('#password').val()) == '') {
		common.toast('密码不能为空')
		return
	} else if(!$('.user_text').find('i').hasClass('checked')) {
		common.toast('请阅读并同意用户协议')
		return
	}
	swith = true
	common.ajax('/userCore/userReg', {
		shopName: $('.name input').val(),
		phone: $('.phone input').val(),
		password: $('#password').val(),
		mobileCode: $('#code').val()
	}, function(data) {
		swith = false
		if(data.code == 1) {
			localStorage.setItem('userData', JSON.stringify(data.data))
			$('input').blur()
			var wvs, self, launch;
			wvs = plus.webview.all();
			self = plus.webview.currentWebview();
			launch = plus.webview.getLaunchWebview();
			for(var i = 0, len = wvs.length; i < len; i++) {
				if(wvs[i].getURL() == self.getURL() || wvs[i].getURL() == launch.getURL()) {
					continue
				}
				plus.webview.getWebviewById(wvs[i].id).reload()
			}
			plus.webview.close(plus.webview.currentWebview().id);
			plus.webview.close(plus.webview.getWebviewById('../login/login.html'))
		} else {
			if(data.resultMsg) {
				common.toast(data.resultMsg)
			} else {
				console.log(data)
			}
		}
	})

})

//用户协议
$(".user_text").on("tap", function(e) {
	if(e.target.className == 'clsopen') {
		return
	}
	$(this).find('i').hasClass('checked') ? $(this).find('i').removeClass('checked') : $(this).find('i').addClass('checked')
})

//倒计时
function jishi() {
	if(temp >= 0) {
		$('.getCode').text(temp + "s")
		setTimeout(jishi, 1000)
	} else {
		temp = num
		swithCode = false
		$('.getCode').text('重新获取')
	}
	temp--
}